package com.lxc.graduation.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lxc.graduation.entity.domain.User;
import com.lxc.graduation.service.UserService;
import com.lxc.graduation.utils.JsonData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: ck
 * @Description:
 * @Date: Create in 20:02 2021/1/19
 */
@RestController
@RequestMapping("/api/pub/v1/user")
@Slf4j
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("login")
    public JsonData login(@RequestBody User user)
    {
        User user1 = userService.findByNameAndPwd(user.getName(),user.getPwd());
        return user1!=null?JsonData.buildSuccess("登陆成功"):JsonData.buildError("登陆失败");
    }


    @RequestMapping("register")
    public JsonData register(@RequestBody User user)
    {
        User user1 = userService.findByNameAndPwd(user.getName(),user.getPwd());
        if(user1!=null)
        {
            return JsonData.buildError("用户已存在");
        }
        else
        {
            userService.insert(user);
            return JsonData.buildSuccess("注册成功");
        }

    }




}
